package main

import (
	"./framework"
	"./global"
	"github.com/bwmarrin/snowflake"
	"log"
	"time"
)

func main() {
	log.SetFlags(log.Lshortfile)
	err := global.LoadConfig()
	if err != nil {
		println("加载配置文件失败：" + err.Error())
		return
	}

	err = global.SetLogger()
	if err != nil {
		println("设置日志记录失败：" + err.Error())
	}

	err = global.OpenDB()
	if err != nil {
		println("连接数据库失败：" + err.Error())
	}

	//token参数配置
	tokenSection := global.Config.Section("token")
	global.TokenToption.Key = tokenSection.Key("key").String()
	global.TokenToption.Method = tokenSection.Key("method").String()
	global.TokenToption.ParamName = tokenSection.Key("paramName").String()

	//ID节点生成器赋值
	global.IDNode, err = snowflake.NewNode(0)
	if err != nil {
		global.Logger.Fatal("global.IDNode变量赋值失败：" + err.Error())
		return
	}

	//设置时间时区
	global.TimeLocal, err = time.LoadLocation("Local")
	if err != nil {
		global.Logger.Fatal("设置时区失败：" + err.Error())
		return
	}

	//启动框架
	err = framework.Start()
	if err != nil {
		global.Logger.Error("echo框架启动失败：" + err.Error())
		return
	}
}
